import request from '@/utils/request'

// 生产线相关接口
export function getProductionLines(params) {
  return request({
    url: '/processLine/findByPage',
    method: 'get',
    params
  })
}

export function getProductionLineById(lineId) {
  return request.get( `/processLine/detail/${lineId}`)
}
export function getRunningProductionLine() {
  return request.get( `/processLine/running`)
}

export function getFreeProductionLine() {
  return request.get( `/processLine/free`)
}
export function availableProcessTask(params) {
  return request({
    url: '/processTask/availableProcessTask',
    method: 'get',
    params
  })
}
// 工序任务相关接口
export function getProcessTasks(params) {
  return request({
    url: '/processTask/findByPage',
    method: 'get',
    params
  })
}
export function searchProcessTasks(params) {
  return request({
    url: '/processTask/searchAnd',
    method: 'get',
    params
  })
}
export function updateProcessTasks(data ) {
  return request({
    url: '/processTask/update',
    method: 'post',
    data
  })
}
export function getProcessTaskById(taskId) {
  return request({
    url: `/processTask/detail/${taskId}`,
    method: 'get'
  })
}

// 生产订单相关接口
export function getProductionOrders(params) {
  return request({
    url: '/productionOrder/findByPage',
    method: 'get',
    params
  })
}

export function getProductionOrderById(orderId) {
  return request({
    url: `/productionOrder/one/${orderId}`,
    method: 'get'
  })
}

// 添加订单
export function addProductionOrder(data) {
  return request({
    url: '/productionOrder/add',
    method: 'post',
    data
  })
}
export function addProductionLine(data) {
  return request({
    url: '/processLine/add',
    method: 'post',
    data
  })
}
// 更新订单
export function updateProductionOrder(data) {
  return request({
    url: '/productionOrder/update',
    method: 'put',
    data
  })
}

export function updateProductionLine(data) {
  return request({
    url: '/processLine/update',
    method: 'put',
    data
  })
}


// 搜索订单
export function searchProductionOrder(params) {
  return request({
    url: '/productionOrder/search',
    method: 'get',
    params
  })
}
export function processHistoryall() {
  return request({
    url: `/processHistory/week`,
    method: 'get'
  })
}



// 获取空闲订单列表
export function getFreeOrders() {
  return request({
    url: '/productionOrder/free',
    method: 'get'
  })
}

// 分配生产线给订单
export function assignOrderToLine(id,productionLineId) {
  return request({
    url: '/productionOrder/addToProduction',
    method: 'post',
    params: {
      id:id,
      productionLineId:productionLineId,
    },
  })
}

// 设备相关接口
export function getEquipments(params) {
  return request({
    url: '/equipment',
    method: 'get',
    params
  })
}
export function findStatusByPage(params) {
  return request({
    url: '/equipment/status',
    method: 'get',
    params
  })
}

export function findStatusAndNameByPage(params) {
  return request({
    url: '/equipment/searchAnd',
    method: 'get',
    params
  })
}
export function getEquipmentById(id) {
  return request({
    url: `/equipment/${id}`,
    method: 'get'
  })
}

export function addEquipment(data) {
  return request({
    url: '/equipment',
    method: 'post',
    data
  })
}

export function updateEquipment(data) {
  return request({
    url: '/equipment',
    method: 'put',
    data
  })
}

export function deleteEquipment(id) {
  return request({
    url: `/equipment/${id}`,
    method: 'delete'
  })
}
export function deleteProcessLine(id) {
  return request({
    url: `processLine/delete/${id}`,
    method: 'delete'
  })
}
export function getFreeEquipments() {
  return request({
    url: '/equipment/free',
    method: 'get'
  })
}

export function addEquipmentToProcessTask(id, processTaskId) {
  return request({
    url: '/equipment/addToProcessTask',
    method: 'post',
    params: {
      id,
      processTaskId
    }
  })
}

export function removeEquipmentFromProcessTask(id) {
  return request({
    url: '/equipment/removeFromProcessTask',
    method: 'post',
    params: {
      id
    }
  })
}

// 获取正在执行的订单列表
export function getRunningOrders() {
  return request({
    url: '/productionOrder/running',
    method: 'get'
  })
}

// 将订单移出生产线（停止订单执行）
export function removeOrderFromLine(id) {
  return request({
    url: '/productionOrder/removeFromLine',
    method: 'post',
    params: {
      id
    }
  })
}
export function deleteOrder(id) {
  return request({
    url: `/productionOrder/delete/${id}`,
    method: 'delete'
  })
}


export function EquipmentSetFault(id) {
  return request({
    url: '/equipment/setFault',
    method: 'post',
    params: {
      id
    }
  })
}

//删除工序区
export function deleteProcessTaskById(id) {
  return request({
    url: `/processTask/delete/${id}`,
    method: 'delete'
  })
}

// 设备名搜索
export function searchEquipmentByName(params) {
  return request({
    url: '/equipment/search',
    method: 'get',
    params
  })
}

// 生产记录相关接口
export function getProcessHistories(params) {
  return request({
    url: '/processHistory',
    method: 'get',
    params
  })
}

export function getProcessHistoryById(id) {
  return request({
    url: `/processHistory/${id}`,
    method: 'get'
  })
}

export function getProcessHistoryWeek() {
  return request({
    url: '/processHistory/week',
    method: 'get'
  })
}

export function addProcessHistory(data) {
  return request({
    url: '/processHistory',
    method: 'post',
    data
  })
}

export function updateProcessHistory(data) {
  return request({
    url: '/processHistory',
    method: 'put',
    data
  })
}

export function deleteProcessHistory(id) {
  return request({
    url: `/processHistory/${id}`,
    method: 'delete'
  })
}

// 设备参数记录相关接口
export function getProcessParameters(params) {
  return request({
    url: '/processParameter',
    method: 'get',
    params
  })
}

export function getProcessParameterById(id) {
  return request({
    url: `/processParameter/${id}`,
    method: 'get'
  })
}

export function addProcessParameter(data) {
  return request({
    url: '/processParameter',
    method: 'post',
    data
  })
}

export function updateProcessParameter(data) {
  return request({
    url: '/processParameter',
    method: 'put',
    data
  })
}

export function deleteProcessParameter(id) {
  return request({
    url: `/processParameter/${id}`,
    method: 'delete'
  })
}

// 订单加急和取消加急接口
export function setPriorityUrgent(id) {
  return request({
    url: '/productionOrder/setPriorityUrgent',
    method: 'post',
    params: { id }
  })
}

export function cancelPriorityUrgent(id) {
  return request({
    url: '/productionOrder/cancelPriorityUrgent',
    method: 'post',
    params: { id }
  })
}
